package zhtt.controller;

import org.springframework.web.bind.annotation.*;
import zhtt.entity.User;
import java.util.*;

/**
 * Created by zhaott on 2018/5/18.
 */
@RestController
@RequestMapping("/user")
public class UserController {

    /**
     * 根据id获取详情
     * @param id
     * @return
     */
    @RequestMapping(value = "/getById",method = RequestMethod.GET)
    public User deails(@RequestParam("id") String id){
        return new User(id);
    }

    /**
     * 根据多个ID获取详情
     * @param ids
     * @return
     */
    @RequestMapping(value = "/getByIds",method = RequestMethod.GET)
    public List<User> getByIds(@RequestParam("id") List<String> ids){
        List<User> userList=new ArrayList<>();
        for(String id:ids){
            userList.add(new User(id));
        }
        return userList;
    }

    /**
     * 根据多个ID获取详情
     * @param ids
     * @return
     */
    @RequestMapping(value = "/getByIds2",method = RequestMethod.GET)
    public List<User> getByIds2(@RequestParam("id") String[] ids){
        List<User> userList=new ArrayList<User>();
        for(String id:ids){
            userList.add(new User(id));
        }
        return userList;
    }

    /**
     * 查询
     * @param map
     * @return
     */
    @RequestMapping(value = "/query",method = RequestMethod.POST)
    public Map<String,String> query(Map<String,String> map){
        return map;
    }

    /**
     * 对象保存
     * @param user
     * @return
     */
    @RequestMapping(value = "/save",method = RequestMethod.POST)
    public User save(@RequestBody User user){
        return user;
    }

    /**
     * 分页查询
     * @param pageNo
     * @param pageSize
     * @param user
     * @return
     */
    @RequestMapping(value="/paging",method = RequestMethod.POST)
    public List<User> paging(@RequestParam(required = false,defaultValue = "1") int pageNo,
                            @RequestParam(required = false,defaultValue = "15") int pageSize,
                            @RequestBody User user){
        List<User> userList=new ArrayList<User>();
        userList.add(user);
        return userList;

    }

    /**
     * 批量保存数据
     * @param userList
     * @return
     */
    @RequestMapping(value = "/saves",method = RequestMethod.POST)
    public List<User> saves(@RequestBody List<User> userList){
        return userList;
    }

}
